package dongshi.daddy.singleton.lazydcl;

public class DclLazy {
    private static DclLazy instance;
    private static final Object mutexLock = new Object();

    // 私有化构造函数，防止外部创建
    private DclLazy() {}

    public static DclLazy getInstance() {
        // 第一次检查实例是否创建
        if (instance == null) {
            // 获取锁
            synchronized (mutexLock) {
                // 第二次检查实例是否创建
                if (instance == null) {
                    System.out.println("实例初始化开始了");
                    // 创建实例
                    instance = new DclLazy();
                    System.out.println("实例初始化结束了");
                }
            }
        }
        return instance;
    }
}
